package com.koron.operation.classes.shift.service.impl;


import com.github.pagehelper.PageInfo;
import com.koron.bean.query.PageQuery;
import com.koron.operation.classes.shift.bean.po.ClassesDutyRecord;
import com.koron.operation.classes.shift.bean.query.DutyRecordQuery;
import com.koron.operation.classes.shift.mapper.ClassesDutyRecordMapper;
import com.koron.operation.classes.shift.service.ClassesDutyRecordService;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * 值班记录(ClassesDutyRecord)表服务实现类
 *
 * @author jzp
 * @since 2022-04-01 11:37:38
 */
@Service
public class ClassesDutyRecordServiceImpl implements ClassesDutyRecordService {

    /**
     * 通过ID查询单条数据
     */
    @Override
    @TaskAnnotation("getById")
    public ClassesDutyRecord getById(SessionFactory factory, String id) {
        ClassesDutyRecordMapper mapper = factory.getMapper(ClassesDutyRecordMapper.class);
        return mapper.selectById(id);
    }

    /**
     * 查询所有数据
     */
    @Override
    @TaskAnnotation("list")
    public List<ClassesDutyRecord> list(SessionFactory factory, DutyRecordQuery query) {
        ClassesDutyRecordMapper mapper = factory.getMapper(ClassesDutyRecordMapper.class);
        return mapper.selectList(query);
    }

    @Override
    @TaskAnnotation("page")
    public PageInfo<ClassesDutyRecord> page(SessionFactory factory, PageQuery pageQuery, DutyRecordQuery query) {
        return ClassesDutyRecordService.super.page(factory, pageQuery, query);
    }

    /**
     * 新增数据
     */
    @Override
    @TaskAnnotation("save")
    public boolean save(SessionFactory factory, ClassesDutyRecord classesDutyRecord) {
        ClassesDutyRecordMapper mapper = factory.getMapper(ClassesDutyRecordMapper.class);
        return mapper.insertOrUpdate(classesDutyRecord) > 0;
    }

    @Override
    @TaskAnnotation("saveBatch")
    public boolean saveBatch(SessionFactory factory, List<ClassesDutyRecord> classesDutyRecords) {
        if (CollectionUtils.isEmpty(classesDutyRecords)) {
            return false;
        }
        ClassesDutyRecordMapper mapper = factory.getMapper(ClassesDutyRecordMapper.class);
        return mapper.insertOrUpdateBatch(classesDutyRecords) > 0;
    }

    /**
     * 修改数据
     */
    @Override
    @TaskAnnotation("update")
    public boolean update(SessionFactory factory, ClassesDutyRecord classesDutyRecord) {
        ClassesDutyRecordMapper mapper = factory.getMapper(ClassesDutyRecordMapper.class);
        return mapper.update(classesDutyRecord) > 0;
    }

    /**
     * 通过主键删除数据
     */
    @Override
    @TaskAnnotation("deleteById")
    public boolean deleteById(SessionFactory factory, String id) {
        ClassesDutyRecordMapper mapper = factory.getMapper(ClassesDutyRecordMapper.class);
        return mapper.hidden(id) > 0;
    }
}
